package cn.ly.link.data;

import cn.ly.link.Node;

public class DoubleLinkList<E> {
	private Node first;
	private Node last;
	
	public DoubleLinkList(){
		this.first = null;
		this.last = null;
	}
	
	public void insertLast(E e){
		Node newNode = new Node(e);
		if(isEmpty()){
			first = newNode;
		}else{
			last.next = newNode;
		}
		last = newNode;
	}
	
	public E removeFirst(){
		Node temp = this.first;
		if(first.next == null){
			last = null;
		}
		first = first.next;
		return (E)temp.data;
	}
	
	public boolean isEmpty(){
		return first == null;
	}
	
	public void display(){
		Node cur = first;
		while(cur != null){
			cur.display();
			cur = cur.next;
		}
		System.out.println();
	}
	

}
